﻿using Microsoft.International.Converters.PinYinConverter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace PSI.Helper {
    public class PinYinHelper {
        /// <summary>
        /// 返回一个字符串的拼音字头
        /// </summary>
        /// <param name="str">输入的中文</param>
        /// <param name="capitalLetters">true: 拼音字头是大写, false: 拼音字头是小写</param>
        /// <returns>拼音字头</returns>
        public string ConvertToPinYinZiTou(string str, bool capitalLetters = false) {
            if (string.IsNullOrEmpty(str)) {
                return string.Empty;
            }

            var sb = new StringBuilder();
            foreach (var item in str) {
                var cc = new ChineseChar(item);
                sb.Append(cc.Pinyins[0].Substring(0, 1));
            }

            return capitalLetters ? sb.ToString() : sb.ToString().ToLower();
        }
    }
}
